package neca.tmazo.vista.vistaGUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

/**
 * 
 * @author neca
 *
 */
public class InfoPanel extends JPanel {

	private JLabel text;
	private JLabel errorIcon;
	private JLabel infoIcon;
	public InfoPanel() 
	{
		setBorder(new LineBorder(Color.LIGHT_GRAY));
		errorIcon=new JLabel(ImageManager.getImage(ImageManager.IMAGE_ERROR_ICON));
		errorIcon.setBounds(10,10,70,70);
		infoIcon=new JLabel(ImageManager.getImage(ImageManager.IMAGE_INFO_ICON));
		infoIcon.setBounds(10,10,70,70);
		this.setBackground(Color.DARK_GRAY);
		this.setVisible(false);
		this.setFocusable(false);
		this.setBounds(184, 63, 406, 385);
		this.setLayout(null);
		
		Border paddingBorder = BorderFactory.createEmptyBorder(0,5,0,5);
		text= new JLabel();
		text.setText("");
		text.setBorder(BorderFactory.createCompoundBorder(getBorder(),paddingBorder));
		text.setHorizontalAlignment(SwingConstants.CENTER);
		text.setFont(new Font("Tahoma", Font.PLAIN, 17));
		text.setBounds(10, 114, 386, 182);
		text.setOpaque(true);
		text.setBackground(new Color(220,220,220));
		this.add(text);
		
		JButton btnNewButton = new JButton("Cerrar");
		btnNewButton.setBackground(Color.DARK_GRAY);
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setVisible(false);
			}
		});
		btnNewButton.setBounds(140, 320, 120, 40);
		this.add(btnNewButton);
		this.add(errorIcon);
		this.add(infoIcon);
	}
	public void setInfo(String text,boolean error)
	{
		this.text.setText("<html>"+text+"</html>");
		if(error) 
		{
			this.setBackground(Color.DARK_GRAY);
			this.errorIcon.setVisible(true);
			this.infoIcon.setVisible(false);
		}
		else
		{
			this.setBackground(Color.DARK_GRAY);
			this.errorIcon.setVisible(false);
			this.infoIcon.setVisible(true);
		} 
	}
}
